<template>
  <view class="container">
    <!-- 顶部导航栏 -->
    <view class="navbar">
      <view class="back-button" @click="goBack">
        <text class="back-icon">←</text>
        <text class="title">动画片</text>
      </view>
    </view>

    <!-- 列表内容 -->
    <view class="content">
      <view class="list">
        <view
          class="list-item"
          v-for="(item, index) in items"
          :key="index"
          @tap="jumpNav(item, index)"
        >
          <view class="item-image">
            <!-- 使用 require 引入图片 -->
            <image :src="item.image ? item.image : require('@/static/img/yes.png')" class="item-image"></image>
          </view>
          <view class="item-text">{{ item.drawbook }}</view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      items: [],
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    loadData() {
      uni.request({
        header: {
          'Content-Type': 'application/json; charset=utf-8'
        },
        url: getApp().globalData.baseUrl + "getDrawList",
        method: 'POST',
        data: {},
        dataType: 'json',
        success: (res) => {
          if (res.data.code === 0) {
            this.items = res.data.data || [];
          } else {
      
          }
        },
        fail: () => {
          uni.showToast({
            title: '请求失败',
            icon: 'none',
            duration: 1000
          });
        }
      });
    },
    jumpNav(item, index) {
      // 获取当前项的 creator
      const currentCreator = this.items[index].creator || '';
      
      // 构造跳转 URL
      const url = `/pages/reapp/learnCenter/ideaPage/ideaPage?name=${encodeURIComponent(item.drawbook)}&creator=${encodeURIComponent(currentCreator)}&image=${encodeURIComponent(item.image)}`;
      
      // 执行跳转
      uni.navigateTo({
        url: url
      });
    },
    goBack() {
      uni.navigateBack();
    },
  },
};
</script>

<style scoped>
.container {
  background-color: #ffe79e;
  min-height: 100vh;
  padding: 0;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx 30rpx;
  background-color: #ffe79e;
  border-bottom: 1rpx solid #f5f5f5;
}

.back-button {
  display: flex;
  align-items: center;
}

.back-icon {
  font-size: 40rpx;
  color: #333;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
  margin-left: 10rpx;
}

.content {
  padding: 20rpx;
}

.list {
  display: flex;
  flex-direction: column;
}

.list-item {
  display: flex;
  align-items: center;
  background-color: #fff;
  border-radius: 20rpx;
  margin-bottom: 20rpx;
  padding: 20rpx;
  box-shadow: 0 4rpx 10rpx rgba(0, 0, 0, 0.1);
}

.item-image {
  width: 120rpx;
  height: 80rpx;
  margin-right: 20rpx;
  border-radius: 10rpx;
  overflow: hidden;
}

.item-image image {
  width: 100%;
  height: 100%;
}

.item-text {
  font-size: 32rpx;
  color: #333;
  flex: 1;
}
</style>